<?php


/**
 * Notes:
 * PROJECT_NAME : ERP v1.0.0.042823
 * User: 夏鱼儿<397072174@qq.com>
 * Date: 2023/5/15
 * Time: 9:21
 */

namespace app\model;

use think\Model;

class BillNote extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'add_time';

    protected $updateTime = 'update_time';

    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'store_id',
        'tax_rate',//税率
        'after_tax_money',//税后金额
        'cost_money',//成本金额
        'net_income',//净收入
        'update_time',
        'remarks',//备注
        'uid',//未知
    ];

    /**
     * 构造器
     * @param $value
     * @return string
     */
    public function getSettlementStatusTextAttr($value, $data)
    {
        $status = [1 => '未结算', 2 => '已结算'];
        return $status[$data['settlement_status']];
    }

    /**
     * 构造器
     * @param $value
     * @return string
     */
    public function getTypeTextAttr($value, $data)
    {
        $types = [1 => '服务', 2 => '商品'];
        return $types[$data['type']];
    }

    /**
     * 构造器
     * @param $value
     * @return string
     */
    public function getBudgetTypeTextAttr($value, $data)
    {
        $BudgetType = [1 => '收', 2 => '支'];
        return $BudgetType[1];
    }

    /**
     * 关联缴费表
     * @return \think\model\relation\BelongsTo
     */
    public function payOrder()
    {
        $bing = [
            'order_no' => "order_no",
            'pay_time' => "pay_time",
        ];
        return $this->belongsTo(PayOrder::class, 'order_id', 'order_id')->bind($bing);
    }
}